import { MiddlewareConsumer, Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from '@nestjs/config';
import { PrismaModule } from './common/prisma/prisma.module';
import { UsersModule } from './user/user.module';
import { AuthMiddleware } from './common/middlewares/auth.middleware';
import { BullModule } from '@nestjs/bull';
import { ChatModule } from './chat/chat.module';
// import { MailModule } from './mail/mail.module';
import { PostsModule } from './posts/posts.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      envFilePath: [`.env.${process.env.NODE_ENV}`, '.env'],
      isGlobal: true,
    }),
    BullModule.forRoot({
      redis: {
        host: '211.149.161.30',
        username: 'default', // needs Redis >= 6
        port: 6379,
        password: 'ReD1s',
        db: 8,
      },
    }),
    ChatModule,
    PrismaModule,
    // MailModule,
    UsersModule,
    PostsModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {
  configure(consumer: MiddlewareConsumer) {
    // 应用中间件到所有路由
    consumer.apply(AuthMiddleware).forRoutes('*');

    // 或者应用到特定路由
    // consumer.apply(AuthMiddleware).forRoutes('users');
  }
}

// export class AppModule implements NestModule {
//   configure(consumer: MiddlewareConsumer) {
//     // 应用中间件到所有路由
//     consumer.apply(LoggerMiddleware).forRoutes('*');

//     // 或者应用到特定路由
//     // consumer.apply(LoggerMiddleware).forRoutes('cats');
//   }
// }
